// 导入用户集合
const {
    News
} = require('../../../model/news');
const moment = require('moment')
const {
    decodeToken
} = require('../../../middleGuard/jwt.js')

module.exports = async (req, res) => {
    const userId = decodeToken(req.headers.authorization).userId
    News.create({
        ...req.body,
        user: userId,
        createTime: moment().format('YYYY-MM-DD HH:mm:ss')
    }).then(item => {
        res.json({
            data: item,
            message: '添加成功！'
        })
    }).catch((err) => {
        res.status(403)
        res.json({
            log: err,
            message: '添加失败！'
        })
    })
}
